<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>新增账号
                        </li>
                    </ol>
                </div>
            </div>
            <div id="page-wrapper">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form method="post" enctype="multipart/form-data" name="myform">
                        <div class="form-group">
                            <label for="name"><strong>账号名称</strong></label>                            <input type="text" placeholder="请输入邮箱" id="name" class="form-control" name="name" />
                        </div>
                        <div class="form-group">
                            <label for="passwd"><strong>初始密码</strong>(密码为6-16位数字、字母)</label>
                            <input type="text" placeholder="121212" id="passwd" class="form-control" name="passwd" value="121212" />
                        </div>
                        <div class="form-group" id="role">
                            <label for="role"><strong>账号角色</strong>&nbsp;&nbsp;&nbsp;&nbsp;</label></br>
                            <input type="radio" id="hd" name="role" value="hd_admin"/><label for="hd">&nbsp;华道&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <input type="radio" id="bx" name="role" value="bx_admin"/><label for="bx">&nbsp;保险公司&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <input type="radio" id="qy" name="role" value="qy_admin"/><label for="qy">&nbsp;企业人资&nbsp;&nbsp;&nbsp;&nbsp;</label>
                        </div>
                        <div class="form-group" id="companyDiv">
                            <label for="company"><strong>所属公司</strong></label></br>
                            <div id="company">
                                
                            </div>
 <!--                           <button class="btn btn-primary demo_1" type="button" id="confirm">确认</button>-->
                            <input type="hidden" value="" name="b_company_code"> 
                            <input type="hidden" value="" name="company_code"> 
                        </div>
                        <div id="policyno">
                            <label><strong>保单号</strong></label></br>
                            <div id="policynoDiv">  </div>  
                        </div>
                        <div class="form-group">
                            <span class="help-block">权限分配&nbsp;&nbsp;&nbsp;&nbsp;</span>
                            <?foreach($tCData as $v){?>
                            <!--<input type="checkbox" id="active<?=$v['id']?>" name="auth[]" value="<?=$v['id']?>"/><label for="active<?=$v['id']?>">&nbsp;<?=$v['name']?>&nbsp;&nbsp;&nbsp;&nbsp;</label>-->
                            <?}?>
                            <div id="auth"> </div>
                        </div>
                        <button class="btn btn-primary demo_2" type="button" id="submit">添加</button>
                    </form>   
                </div>
                <div class="subviews">
                    <div class="subviews-container"></div>
                </div>
            </div>
            <!-- end: PAGE -->
        </div>
    </div>
</div>
<!-- end: MAIN CONTAINER -->
<script type="text/javascript" src="/plugins/jquery-ui-1.11.4/jquery-ui.min.js"></script>
 <script type="text/javascript" src="/plugins/medialog/mdialog.js"></script><!--medialog -->
 <script type="text/javascript" src="/plugins/medialog/zepto.min.js"></script><!--zepto -->
<script>
$(function(){
    $('input[name="role"]').click(function(){
        var role = $(this).val();
        if(role == 'qy_admin' || role == 'bx_admin'){
            $.get('/admin_admin/company?role='+role,function(obj){
                var html = (
                    '<select name="company">' +
                        '<option value="">=请选择=</option>'
                );   
                $.each(obj.data,function(key,row){
                    html += "<option value='"+row.company_id+"'>"+row.company+"</option>";
                });
                html += (
                    '</select>' 
                );
                $('#company').html(html);
                $('select[name="company"]').on("change",function(){
                    bcompany($(this),role); 
                });
            }); 
        }else{
            $('#company').html(""); 
        }
        rolelist();
    });
    $('#submit').click(function(){
    
        var data = $('form[name="myform"]').serialize();
        $.post('/admin_admin/add',data,function(obj){
            cg_alert_add(obj,'/admin_admin/','/admin_admin/add'); 
        });
    });

})
//保单
function policyno(data){
    $.get('/admin_admin/policy?'+data,function(obj){
        var html = '';
        $.each(obj.data,function(key,row){
            html += '<input type="checkbox" value="'+row.policyno+'" name="policyno[]" />'+row.policyno; 
        });
        $('#policynoDiv').html(html);
    });
}
//权限
function rolelist(){
    var role = $('input[name="role"]:checked').val();
    $.get('/admin_admin/role?role='+role,function(obj){
        var html = '';
        $.each(obj.data,function(key,row){
            html += '<input type="checkbox" value="'+row.id+'" name="auth[]"/>'+row.name;
        });
        $('#auth').html(html);
    });

}

function bcompany(obj,role){
    var company_id = obj.val();
    $.get('/admin_admin/bcompany?cid='+company_id+'&role='+role,function(obj){
        $('select[name="bcompany"]').remove();
        if(obj.status == 0){return false;}
        var html = (
            '<select name="bcompany">'+    
                '<option value="">==请选择==</option>'
        ); 
        $.each(obj.data,function(key,row){
            html += '<option value="'+row.bc_id+'">'+row.bc_name+'</option>'; 
        });
        html += '</select>';
        $('#company').append(html);

        var role = $('input[name="role"]:checked').val();
        if(role == 'qy_admin'){
            policyno('c_id='+company_id);
        }else{
            policyno('insurance_no='+company_id);
        }

        $('select[name="bcompany"]').on('change',function(){
            var role = $('input[name="role"]:checked').val();
            if(role == 'qy_admin'){
                var bc_id = $(this).val();
                policyno('bc_id='+bc_id);
            }else{
                var bc_id = $(this).val();
                policyno('insurance_no='+company_id+'&organition_no='+bc_id);
            }
        });
    });
}
</script>

<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
